import Config
from public.public import *


def send_soldiers(left, top, x, y, soldier_position, num):
    """
    向目标城池派遣指定军队指定数量
    :param left: App的left坐标
    :param top: App的top坐标
    :param x: 城池的x坐标
    :param y: 城池的y坐标
    :param soldier_position: 兵种坐标
    :param num: 兵种数量
    :return:
    """
    # 输入坐标打开城市命令界面
    chose_city(left, top, x, y)
    # 点击派遣按钮
    _ = Config.DiTuConfig.SendButton
    mouse_move_to_and_click(left + _[0], top + _[1])

    # 选择兵种进行输入
    time.sleep(1)
    mouse_move_to_and_click(left + soldier_position[0], top + soldier_position[1])

    clear_and_send_keys(num, check=False)

    # 点击出征进行派遣
    _ = Config.JiaoChang.ChuZheng
    mouse_move_to_and_click(left + _[0], top + _[1])

    # 关闭校场界面
    time.sleep(2)
    _ = Config.JiaoChang.CloseButton1
    mouse_move_to_and_click(left + _[0], top + _[1])


def send_soldier_to_main(soldier_position=Config.JiaoChang.QingQiText, num=1000):
    """
    将兵派遣到主城
    :param soldier_position: 兵种位置
    :param num: 兵种数量
    :return:
    """
    send_soldier_to_city(city=None, soldier_position=soldier_position, num=num)


def send_soldier_to_city(city=None, soldier_position=Config.JiaoChang.QingQiText, num=1000):
    """
    将兵派遣到主城
    :param city:
    :param soldier_position: 兵种位置
    :param num: 兵种数量
    :return:
    """
    time.sleep(10)
    control = get_control_by_level([0, 0, 0, 0, 0, 0], base_name="热血三国-")
    left, top, width, height = get_control_position(control)
    cities = get_soldier_cities(control)
    if city is None:
        city = get_main_city(control)
    for _ in cities:
        if _ == city:
            continue
        entry_city(left, top, _[0], _[1], cityin=False)
        send_soldiers(left, top, city[0], city[1], soldier_position, num)


def send_soldier_to_soldier_cities(soldier_type=Config.JiaoChang.YiBingText, num=36000):
    time.sleep(10)
    control = get_control_by_level([0, 0, 0, 0, 0, 0], base_name="热血三国-")
    left, top, width, height = get_control_position(control)
    cities = get_soldier_cities(control)
    if get_solider_cities_reserve_config(control):
        cities.reverse()
    for _ in cities:
        send_soldiers(left, top, _[0], _[1], soldier_type, num)


if __name__ == "__main__":
    # send_soldier_to_main(soldier_position=Config.JiaoChang.GongJianText, num=36000)
    # send_soldier_to_main(soldier_position=Config.JiaoChang.QingQiText, num=12000)
    # send_soldier_to_main(soldier_position=Config.JiaoChang.ZiZhongText, num=1000)
    # send_soldier_to_main(soldier_position=Config.JiaoChang.TieQiText, num=6000)
    # send_soldier_to_city(city=[415, 255], soldier_position=Config.JiaoChang.ChuangNuText, num=6000)
    # send_soldier_to_city(city=[415, 255], soldier_position=Config.JiaoChang.QingQiText, num=24000)
    # send_soldier_to_city(city=[415, 255], soldier_position=Config.JiaoChang.TieQiText, num=24000)
    send_soldier_to_city(city=[399, 233], soldier_position=Config.JiaoChang.QingQiText, num=24000)
    # send_soldier_to_city(city=[415, 255], soldier_position=Config.JiaoChang.ChuangNuText, num=6000)
    # send_soldier_to_city(city=[415, 255], soldier_position=Config.JiaoChang.ZiZhongText, num=24000)
    # send_soldier_to_soldier_cities()
    # send_soldier_to_city(city=[320, 197], soldier_position=Config.JiaoChang.ZiZhongText, num=12000)
    # send_soldier_to_city(city=[324, 195], soldier_position=Config.JiaoChang.QingQiText, num=24000)
    # send_soldier_to_city(city=[324, 195], soldier_position=Config.JiaoChang.GongJianText, num=24000)
    # send_soldier_to_city(city=[238, 308], soldier_position=Config.JiaoChang.ChuangNuText, num=12000)
    # send_soldier_to_city(city=[238, 308], soldier_position=Config.JiaoChang.ZiZhongText, num=12000)
